<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{	
	public $assign = [];
	public function admin()
	{
		return view('admin.index');
	}
	public function login()
	{
		return view('admin.login');
	}

	public function doLogin(Request $request)
	{
		$name = $request->post('name');
		$pwd = $request->post('pwd');
		$pd = md6($pwd);
		$model_users = new \App\Model\Users();
		$users = $model_users->getUsers($name);
		if (!empty($users)) {
			if($pd == $users->pwd){
				//存session
				$key = 'login_user';
				session([$key => $users]);
				echo "<script>alert('ok');window.location.href='/admin/index1'</script>";	
			}
			echo "<script>alert('密码错误');window.location.href='/admin/login'</script>";
		} else {
			echo "<script>alert('用户名错误');window.location.href='/admin/login'</script>";
		}
	}


	//退出登录
	public function loginOut()
	{
		$key = 'login_user';
		session()->forget($key);
		return redirect('/admin/login');
	}


}



















?>